package com.tsmti.tags.form;


import javax.servlet.jsp.JspException;

import com.tsmti.tags.form.support.CustomBindStatus;
import org.springframework.beans.PropertyAccessor;
import org.springframework.web.servlet.support.BindStatus;

/**
 * @Package：com.tsmti.tags.form
 * @Class：TextareaTag
 * @Description： TODO
 * @Author：
 * @Date：Created in 2018/3/14 17:15
 * @Company:
 * @Version：
 * @Modified By:
 */
@SuppressWarnings("serial")
public class TextareaTag extends org.springframework.web.servlet.tags.form.TextareaTag {
	private BindStatus bindStatus = null;
	/**
	 * 是否嵌套使用Form自定的模型，模式为真,nested为false,需要设置对应字段为空字符串否则报错；
	 */
	private Boolean nested = true;
	/**
	 *  绑定数据字典类型，数据字典优先
	 */
	private String dict = "";
	/**
	 * 1,bean
	 * 2,通过参数获取。3.获取getAttribute中的值
	 */
	private String valueWay = "";
	/**
	 * 默认值
	 */
	private String defaultValue = "";


	@Override
	protected BindStatus getBindStatus() throws JspException {
		if (this.bindStatus == null) {
			String nestedPath = "";
			if (nested) {
				nestedPath = getNestedPath();
			}
			String pathToUse = (nestedPath != null ? nestedPath + getPath() : getPath());
			if (pathToUse.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) {
				pathToUse = pathToUse.substring(0, pathToUse.length() - 1);
			}
			this.bindStatus = CustomBindStatus.create(pageContext, pathToUse, getRequestContext(), false, nested,
					valueWay, defaultValue);
		}
		return this.bindStatus;
	}

	public Boolean getNested() {
		return nested;
	}

	public void setNested(Boolean nested) {
		this.nested = nested;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getValueWay() {
		return valueWay;
	}

	public void setValueWay(String valueWay) {
		this.valueWay = valueWay;
	}

	@Override
	public void doFinally() {
		super.doFinally();
		this.bindStatus = null;
	}
}
